import Vue from "vue";
import VueRouter from "vue-router";

import Reg from "../components/Reg";
import Login from "../components/Login";
import Home from "../components/Home";

//接口测试
import Test from "../components/Test";

//Home下的二级路由 (各自导航页)
import Index from "../components/home/Ke.vue";
import News from "../components/home/Jie.vue";
import Question from "../components/home/Di.vue";
import Game from "../components/home/Yang.vue";
import My from "../components/home/Xin.vue";

//三级路由（各导航页下的子页面）
import Xininfo from "./modules/xininfo";
import Keindex from "./modules/ke";
import ForgetPassword from "@/components/home/Yang/ForgetPassword";

/* import Keson from '../components/home/Ke/keson.Vue' */
/* import Xininfo from "./xininfo"; */
import Diinfo from "./modules/diinfo";
import Yanginfo from "./modules/Yanginfo";
import Jieson from "./jieson";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    // 重定向
    redirect: "/swiper",
  },
  {
    path: "/reg",
    component: Reg,
  },
  {
    path: "/login",
    component: Login,
  },
  {
    path: "/forgetpassword",
    component: ForgetPassword
  },
  {
    path: "/home/game/index",
    component: () => import("../components/home/Yang/Index.vue"),
  },
  {
    path: "/home",
    component: Home,
    // 子路由
    children: [
      {
        path: "/home",
        redirect: "/home/index",
      },
      {
        path: "index",
        component: Index,
      },
      {
        path: "news",
        component: News,
      },
      {
        path: "question",
        component: Question,
      },
      {
        path: "game",
        component: Game,
        children: [...Yanginfo],
      },
      {
        path: "my",
        component: My,
      },
    ],
  },
  {
    path: "/test",
    component: Test,
  },
  ...Keindex,
  {
    path: "/home/index/map",
    component: Map,
  },
  {
    path: "/test",
    component: Test,
  },
  ...Xininfo,
  ...Jieson,
  ...Diinfo,
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

//全局进入页面前拦截
// router.beforeEach((to,from,next)=>{
//   //to 去哪个页面
//   //from ==> 从哪个页面来
//   if(to.path === "/home/my" && !sessionStorage.getItem('token')){
//     next('/login')
//   }else{
//     //无需拦截
//     next()
//   }
// })
export default router;
